#ifndef _ICE_FRAMEWORK_ENGINE_H_
#define _ICE_FRAMEWORK_ENGINE_H_

#include "Framework_Defines.h"
#include "Base_Classes/B_GameStateHandler.h"
#include "Base_Classes/B_GameState.h"

#include "Options/ICE_Options.h"
#include "Options/gs_ICEVideoConfig.h"

class ICE_EventHandler;

class ICEFrameworkEngine : public B_GameStateHandler
{
protected:
	uint32 m_time;
	wchar_t m_windowCaption[256];

public:
	// class constructor
	ICEFrameworkEngine(void);
	// class destructor
	~ICEFrameworkEngine(void);

protected:
	irr::IrrlichtDevice* m_device;    //irrlicht device pointer
	ICE_EventHandler* m_EventHandler;
public:
	// called to start up the irrlicht engine and set up game variables
	//NOTE: leave restartDevice as false, used by ICE_Options only 
	bool Init(const wchar_t *text = ICEFRAMEWORKNAME,
				irr::video::E_DRIVER_TYPE device_type = irr::video::EDT_OPENGL, 
                int res_x = 640, int res_y = 480, bool fullscreen = false, 
				int colordepth = 16, bool stencilbuffer = false, bool restartDevice = false );

	bool OnEvent(irr::SEvent event);

	virtual void* getAsset(char* asset);

	// called in main loop to see if engine is still running
	//  calls Update of current game state (which calls Render() if neccesary)
	bool Update();

	//ICEFrameworkEngine provides some basic framework gamestates (for setting ICE_Options)
	bool RequestStateChange(char* newState);

private:
    void Destroy(); //dont call this directly, call RequestDestroy instead!

	friend class gs_ICEVideoConfig; //allow Video Config to restart m_device
};


//EventHandler stub class-- (Irrlicht specific)
// used to pass events directly back into the ICE framework

class ICE_EventHandler : public irr::IEventReceiver {
    ICEFrameworkEngine* m_pEngine;

protected:
    friend class ICEFrameworkEngine;
    ICE_EventHandler(ICEFrameworkEngine* engine);
    bool OnEvent(irr::SEvent event) ;
};


#endif
